<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // new的作用：第一步、开辟一个新空间（创建一个空对象）2、让函数中的this指向该对象 3、将属性和方法添加给该对象 4、隐式返回该对象
        function Person(name, sex) {
            this.name = name
            this.sex = sex
            this.say = function() {
                console.log('德玛西亚')
            }
        }
        Person.prototype.dance = function() {
            console.log('跳舞')
        }
        var person = new Person('张三', "男")

        class Person2 {
            constructor(name, sex) {
                this.name = name
                this.sex = sex
                this.say = function() {
                    console.log('人在塔在')
                }
            }

            talk() {
                console.log('你是个麻瓜')
            }
        }
        
        Person2.prototype.dance = function() {
            console.log('跳舞')
        }
        var person2 = new Person2('李四', "女")
        console.log(person, person2)
    </script>
</body>
</html>